package com.ysqcould.approval.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.ysqcould.approval.domain.Information;
import com.ysqcould.approval.domain.vo.InformationVo;
import com.ysqcould.approval.mapper.InformationMapper;
import com.ysqcould.approval.service.IInformationService;
import com.ysqcould.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资讯Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@Service
public class InformationServiceImpl implements IInformationService
{
    @Autowired
    private InformationMapper informationMapper;

    /**
     * 查询资讯
     * 
     * @param id 资讯主键
     * @return 资讯
     */
    @Override
    public Information selectInformationById(Long id)
    {
        return informationMapper.selectInformationById(id);
    }

    /**
     * 查询资讯列表
     * 
     * @param information 资讯
     * @return 资讯
     */
    @Override
    public List<InformationVo> selectInformationList(Information information)
    {
        final List<InformationVo> voList = informationMapper.selectInformationList(information);
        voList.forEach(p->{
            if (ObjectUtil.isNotEmpty(p.getPcUrl())){
                p.setPcUrlList(p.getPcUrl().split(";"));
            }
        });
        return voList;
    }

    /**
     * 新增资讯
     * 
     * @param information 资讯
     * @return 结果
     */
    @Override
    public int insertInformation(Information information)
    {
        information.setCreateTime(DateUtils.getNowDate());
        return informationMapper.insertInformation(information);
    }

    /**
     * 修改资讯
     * 
     * @param information 资讯
     * @return 结果
     */
    @Override
    public int updateInformation(Information information)
    {
        information.setUpdateTime(DateUtils.getNowDate());
        return informationMapper.updateInformation(information);
    }

    /**
     * 批量删除资讯
     * 
     * @param ids 需要删除的资讯主键
     * @return 结果
     */
    @Override
    public int deleteInformationByIds(Long[] ids)
    {
        return informationMapper.deleteInformationByIds(ids);
    }

    /**
     * 删除资讯信息
     * 
     * @param id 资讯主键
     * @return 结果
     */
    @Override
    public int deleteInformationById(Long id)
    {
        return informationMapper.deleteInformationById(id);
    }
}
